package com.lsw.jgyf.ui.activity;

import com.lsw.dialog.DialogProgress;
import com.lsw.jgyf.httpapi.HttpApi;
import com.lsw.jgyf.inject.Constants;
import com.lsw.jgyf.ui.base.presenter.BasePresenter;
import com.lsw.util.LogUtils;
import com.lsw.util.ToastUtil;

import javax.inject.Inject;

import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2018/7/10 0010.
 */

public class PhoneDetailsPresenter extends BasePresenter<PhoneDetailsContract.View> implements PhoneDetailsContract.Presenter {
    @Inject
    HttpApi httpApi;


    @Inject
    public PhoneDetailsPresenter() {

    }

    @Override
    public void getData(String id) {
        DialogProgress progress = new DialogProgress(mContext);
        progress.show();
        Disposable disposable = httpApi
                .getPhoneDetails(id)
                .subscribe(baseBean -> {
                    progress.dismiss();
                    if (baseBean.getStatus() == Constants.CODE_SUCESS) {
                        mView.setData(baseBean.getData());
                    } else if (baseBean.getStatus() == Constants.CODE_LOGIN) {
                        ToastUtil.showToast(mContext, "您的登录信息已过期，请重新登录！");
                        mView.openlogin();
                    } else {
                        ToastUtil.showToast(mContext, baseBean.getMessage());
                    }
                }, throwable -> {
                    progress.dismiss();
                    LogUtils.e("TAG_Enroll", throwable.getMessage());
                });
        mCompositeDisposable.add(disposable);
    }

}
